package com.sunricher.telinkblemeshlib.db;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.sunricher.telinkblemeshlib.models.RoomScene;

import java.util.List;

@Database(entities = {RoomScene.class}, version = 1)
public abstract class RoomSceneDatabase extends RoomDatabase {
    public abstract RoomSceneDao roomSceneDao();

    private static volatile RoomSceneDatabase INSTANCE;

    public static RoomSceneDatabase getDatabase(final Context context) {
        if (INSTANCE == null) {
            synchronized (RoomSceneDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            RoomSceneDatabase.class, "room_scene_database").allowMainThreadQueries().build();
                }
            }
        }
        return INSTANCE;
    }

    long insert(RoomScene roomScene) {
        return roomSceneDao().insert(roomScene);
    }

    void insert(List<RoomScene> roomScenes) {
        roomSceneDao().insert(roomScenes);
    }

    List<RoomScene> selectAll() {
        return roomSceneDao().selectAll();
    }

    List<RoomScene> selectAllWithRoomId(int roomId) {
        return roomSceneDao().selectAllWithRoomId(roomId);
    }

    RoomScene select(int roomId, long identifier) {
        return roomSceneDao().select(roomId, identifier);
    }

    void update(RoomScene roomScene) {
        roomSceneDao().update(roomScene);
    }

    void update(List<RoomScene> roomScenes) {
        roomSceneDao().update(roomScenes);
    }

    void deleteWithIdentifier(long identifier) {
        roomSceneDao().deleteWithIdentifier(identifier);
    }

    void deleteAllWithRoomId(int roomId) {
        roomSceneDao().deleteAllWithRoomId(roomId);
    }

    void deleteAll() {
        roomSceneDao().deleteAll();
    }
}
